package com.yanqu.road.server.manger.kowloon.battle.role.bullet;

import com.yanqu.road.server.manger.kowloon.battle.KowloonGame;
import com.yanqu.road.server.manger.kowloon.battle.role.enemy.KowloonEnemy;

import java.util.List;

/**
 * 落雷
 */
public class KowloonBulletThunder extends KowloonBullet {

    private int atkNum;

    public KowloonBulletThunder(KowloonGame game) {
        super(game);
    }

    @Override
    public void init() {
        this.atkNum = this.shooter.data.getProperty().getAttackNum();
    }

    @Override
    public void updateAI(double dt) {
        if (this.atkNum > 0) {
            KowloonEnemy enemy = this.getHitEnemy();
            if (enemy != null) {
                this.enemyIds.add(enemy.id);
                enemy.beHurt(this.bulletType, +this.shooter.data.getProperty().getAttack());
                List<KowloonEnemy> enemys = this.getNearEnemys(this.shooter.data.getProperty().getWeaponRadius());
                for (KowloonEnemy e : enemys) {
                    int probability = this.buffParam.getProbability();
                    e.beHurt(this.bulletType, Math.floor(this.shooter.data.getProperty().getAttack() * probability / 1000.0));
                }
                this.atkNum--;
                if (this.atkNum <= 0) {
                    this.destroy();
                }
            }
        }
    }
}
